using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using System.IO;
using <Application>.<Business>;
using <Application>.<Data>;

namespace <Application>
{
    public partial class frm<OwnerU>_<TableU> : System.Web.UI.Page
    {

        private DataView dv<OwnerU>_<TableU>;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack) {
    	<If Loop>
        	<IsFKey>
                Session["<FieldU>_SelectedValue"] = "";
    	</If Loop>

                Session.Remove("dv<OwnerU>_<TableU>");
                Session.Remove("Row");

    	<If Loop>
   		<IsNotText>
   		<And>
   		<IsNotNText>
                cmbFields.Items.Add("<FieldC>");
    	</If Loop>

                cmbCondition.Items.Add("Contains");
                cmbCondition.Items.Add("Equals");
                cmbCondition.Items.Add("Starts with...");
                cmbCondition.Items.Add("More than...");
                cmbCondition.Items.Add("Less than...");
                cmbCondition.Items.Add("Equal or more than...");
                cmbCondition.Items.Add("Equal or less than...");

                cmbRecords.Items.Add("5");
                cmbRecords.Items.Add("10");
                cmbRecords.Items.Add("25");
                cmbRecords.Items.Add("50");
                cmbRecords.Items.Add("100");
                cmbRecords.Items.Add("500");

                LoadGrid<OwnerU>_<TableU>();
            }
        }

    <If Loop>
      <IsFKey>
        private void Load<OwnerU>_<TableU>_<ROwnerU>_<RTableU>ComboBox<MiscTag>(GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow) {
                DropDownList txt<FieldU> = (DropDownList)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    try {
                            <IsFKey>
                        txt<FieldU>.DataSource = <OwnerU>_<TableU>_<ROwnerU>_<RTableU>DataClass<MiscTag>.Select<ROwnerU>_<RTableU>();
                        txt<FieldU>.DataValueField = "<RFieldU>";
                        txt<FieldU>.DataTextField = "<RDisplayFieldU>";
                        txt<FieldU>.DataBind();
                        txt<FieldU>.SelectedValue = Convert.ToString(Session["<FieldU>_SelectedValue"]);
                    }
                        catch (Exception ex)
                    {
                        ec.ShowMessage(ex.Message, " <Head> ");
                    }
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer) {
                DropDownList txtNew<FieldU> = (DropDownList)e.Row.FindControl("txtNew<FieldU>");
                if (txtNew<FieldU> != null) {
                    try {
			    <IsFKey>
                        txtNew<FieldU>.DataSource = <OwnerU>_<TableU>_<ROwnerU>_<RTableU>DataClass<MiscTag>.Select<ROwnerU>_<RTableU>();
                        txtNew<FieldU>.DataValueField = "<RFieldU>";
                        txtNew<FieldU>.DataTextField = "<RDisplayFieldU>";
                        txtNew<FieldU>.DataBind();
                    }
                    catch (Exception ex)
                    {
                        ec.ShowMessage(ex.Message, " <Head> ");
                    }
                }
            }
        }

    </If Loop>
        private void LoadGrid<OwnerU>_<TableU>()
        {
            try {
                if ((Session["dv<OwnerU>_<TableU>"] != null)) {
                    dv<OwnerU>_<TableU> = (DataView)Session["dv<OwnerU>_<TableU>"];
                    // DataView was not found in the session.
                } else {
                    dv<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.SelectAll().DefaultView;
                    Session["dv<OwnerU>_<TableU>"] = dv<OwnerU>_<TableU>;
                }
                if (dv<OwnerU>_<TableU>.Count > 0) {
                    grd<TableU>.DataSource = dv<OwnerU>_<TableU>;
                    grd<TableU>.DataBind();
                }
                if (dv<OwnerU>_<TableU>.Count == 0) {
                    DataTable dt = new DataTable();
                    dt.Rows.Add(dt.NewRow());
            <If Loop>
                <IsComboBox (Db)>
                    dt.Columns.Add("<RDisplayFieldU>", Type.GetType("System.<VBType>"));
                <IsNotComboBox (Db)>
                    dt.Columns.Add("<FieldU>", Type.GetType("System.<VBType>"));
            </If Loop>
                    dv<OwnerU>_<TableU> = dt.DefaultView;
                    Session["dv<OwnerU>_<TableU>"] = dv<OwnerU>_<TableU>;

                    grd<TableU>.DataSource = dv<OwnerU>_<TableU>;
                    grd<TableU>.DataBind();

                    int TotalColumns = grd<TableU>.Rows[0].Cells.Count;
                    grd<TableU>.Rows[0].Cells.Clear();
                    grd<TableU>.Rows[0].Cells.Add(new TableCell());
                    grd<TableU>.Rows[0].Cells[0].ColumnSpan = TotalColumns;
                    grd<TableU>.Rows[0].Cells[0].Text = "No Record Found";
                }
                dv<OwnerU>_<TableU>.Sort = htmlHiddenSortExpression.Value;
            }
            catch (Exception ex)
            {
                ec.ShowMessage(ex.Message, " <Head> ");
            }
        }

        protected void grd<TableU>_RowDataBound(object sender, GridViewRowEventArgs e)
        {
        <If Loop>
          <IsFKey>
            Load<OwnerU>_<TableU>_<ROwnerU>_<RTableU>ComboBox<MiscTag>(e);
        </If Loop>
            if (e.Row.RowType == DataControlRowType.DataRow) {
        <If Loop>
           <IsIdentity>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
        </If Loop>
        <If Loop>
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsCheckBox>
                CheckBox txt<FieldU> = (CheckBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsNumericUpDown>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsDateTimePicker>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsTextBox>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsMaskedTextBox>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsMultilineTextBox>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsRichTextBox>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsComboBox>
                DropDownList txt<FieldU> = (DropDownList)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentity>
           <And>
           <IsPKey>
           <And>
    	   <IsComboBox (Db)>
                DropDownList txt<FieldU> = (DropDownList)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsCheckBox>
                CheckBox txt<FieldU> = (CheckBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsNumericUpDown>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsDateTimePicker>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsTextBox>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsMaskedTextBox>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsMultilineTextBox>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsRichTextBox>
                TextBox txt<FieldU> = (TextBox)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsComboBox>
                DropDownList txt<FieldU> = (DropDownList)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
           <And>
    	   <IsComboBox (Db)>
                DropDownList txt<FieldU> = (DropDownList)e.Row.FindControl("txt<FieldU>");
                if (txt<FieldU> != null) {
                    txt<FieldU>.Enabled = false;
                }
        </If Loop>
            }
        <If Loop>
           <IsIdentity>
            if (e.Row.RowType == DataControlRowType.Footer) {
           <ExitLoop>
        </If Loop>
        <If Loop>
           <IsIdentity>
                TextBox txtNew<FieldU> = (TextBox)e.Row.FindControl("txtNew<FieldU>");
                if (txtNew<FieldU> != null) {
                    txtNew<FieldU>.Enabled = false;
                }
        </If Loop>
        <If Loop>
           <IsIdentity>
            }
           <ExitLoop>
        </If Loop>
        }

        protected void grd<TableU>_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grd<TableU>.EditIndex = -1;
            LoadGrid<OwnerU>_<TableU>();
        }

        protected void grd<TableU>_RowEditing(object sender, GridViewEditEventArgs e)
        {
            grd<TableU>.EditIndex = e.NewEditIndex;
            Edit();
        }

        protected void grd<TableU>_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Session["Row"] = e.RowIndex;
            UpdateRecord();
        }

        protected void grd<TableU>_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Session["Row"] = e.RowIndex;
            DeleteRecord();
        }

        protected void grd<TableU>_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Insert")) {
                InsertRecord();
            }
        }

        protected void grd<TableU>_PreRender(object sender, EventArgs e)
        {
            GridView gv = (GridView)sender;
            GridViewRow gvr = (GridViewRow)gv.BottomPagerRow;
            if (gvr != null) {
                gvr.Visible = true;
            }
        }

        protected void grd<TableU>_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grd<TableU>.PageIndex = e.NewPageIndex;
            LoadGrid<OwnerU>_<TableU>();
        }

        protected void grd<TableU>_Sorting(object sender, GridViewSortEventArgs e)
        {
            htmlHiddenSortExpression.Value = e.SortExpression + " " + GetSortDirection(e.SortExpression);
            LoadGrid<OwnerU>_<TableU>();
        }

        private void Edit()
        {
            try {
                <TableU> cls<OwnerU>_<TableU> = new <TableU>();
		        <If Loop>
		           <IsPKey>
                Label lbl<FieldU> = (Label)grd<TableU>.Rows[grd<TableU>.EditIndex].FindControl("lbl<FieldU>");
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text);
		        </If Loop>
		        <If Loop>
		           <IsNotPKey>
		           <And>
		           <IsIdentity>
                Label lbl<FieldU> = (Label)grd<TableU>.Rows[grd<TableU>.EditIndex].FindControl("lbl<FieldU>");
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text);
		        </If Loop>
		        <If Loop>
		           <IsNotIdentityCount>
		           <And>
		           <IsNotPKeyCount>
                Label lbl<FieldU> = (Label)grd<TableU>.Rows[grd<TableU>.EditIndex].FindControl("lbl<FieldU>");
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text);
		           <ExitLoop>
		        </If Loop>
                cls<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.Select_Record(cls<OwnerU>_<TableU>);

    	<If Loop>
        	<IsFKey>
                Session["<FieldU>_SelectedValue"] = cls<OwnerU>_<TableU>.<FieldU>;
    	</If Loop>

                LoadGrid<OwnerU>_<TableU>();
            } catch {  
            }
        }

        private void InsertRecord()
        {
            try {
    <If Loop>
    	<IsNotIdentity>
    	<And>
    	<IsCheckBox>
                CheckBox txtNew<FieldU> = (CheckBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
    	<IsNotIdentity>
    	<And>
    	<IsNumericUpDown>
                TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
    	<IsNotIdentity>
    	<And>
    	<IsDateTimePicker>
                TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
    	<IsNotIdentity>
    	<And>
    	<IsTextBox>
                TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
    	<IsNotIdentity>
    	<And>
    	<IsMaskedTextBox>
                TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
    	<IsNotIdentity>
    	<And>
    	<IsMultilineTextBox>
                TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
    	<IsNotIdentity>
    	<And>
    	<IsRichTextBox>
                TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
    	<IsNotIdentity>
    	<And>
    	<IsComboBox>
                DropDownList txtNew<FieldU> = (DropDownList)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
    	<IsNotIdentity>
    	<And>
    	<IsComboBox (Db)>
                DropDownList txtNew<FieldU> = (DropDownList)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
    </If Loop>

                <TableU> cls<OwnerU>_<TableU> = new <TableU>();
                if (VerifyDataNew() == true) {
                <If Loop>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    cls<OwnerU>_<TableU>.<FieldU> = txtNew<FieldU>.Checked ? true : false;                        
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.SelectedValue)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.SelectedValue); }
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    cls<OwnerU>_<TableU>.<FieldU> = txtNew<FieldU>.Checked ? true : false;  
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = txtNew<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = txtNew<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = txtNew<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = txtNew<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txtNew<FieldU>.SelectedValue)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.SelectedValue); }
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Checked ? true : false);
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNotNull>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.SelectedValue);
--------------------------------------------------------------------------------------------------------<Comment>
                </If Loop>
                    bool bSucess = false;
                    bSucess = <OwnerU>_<TableU>DataClass.Add(cls<OwnerU>_<TableU>);
                    if (bSucess == true) {
                        Session.Remove("dv<OwnerU>_<TableU>");
                        LoadGrid<OwnerU>_<TableU>();
                    } else {
                        ec.ShowMessage(" Insert failed. ", " <Head> ");
                    }
                }
            } catch {  
            }
        }

        private void UpdateRecord()
        {
            try {
    <If Loop>
    	<IsCheckBox>
                CheckBox txt<FieldU> = (CheckBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsNumericUpDown>
                TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsDateTimePicker>
                TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsTextBox>
                TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsMaskedTextBox>
                TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsMultilineTextBox>
                TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsRichTextBox>
                TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsComboBox>
                DropDownList txt<FieldU> = (DropDownList)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsComboBox (Db)>
                DropDownList txt<FieldU> = (DropDownList)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    </If Loop>

                <TableU> cls<OwnerU>_<TableU> = new <TableU>();
        <If Loop>
           <IsPKey>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
        </If Loop>
        <If Loop>
           <IsNotPKey>
           <And>
           <IsIdentity>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
           <ExitLoop>
        </If Loop>
                if (VerifyData() == true) {
                <If Loop>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Checked ? true : false;                        
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.SelectedValue)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.SelectedValue); }
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Checked ? true : false;  
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.Text)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = txt<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                    if (string.IsNullOrEmpty(txt<FieldU>.SelectedValue)) {
                        cls<OwnerU>_<TableU>.<FieldU> = null;
                    } else {
                        cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.SelectedValue); }
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Checked ? true : false);
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNotNull>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNotNull>
                    cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txt<FieldU>.SelectedValue);
--------------------------------------------------------------------------------------------------------<Comment>
                </If Loop>
                    bool bSucess = false;
                    bSucess = <OwnerU>_<TableU>DataClass.Update(cls<OwnerU>_<TableU>);
                    if (bSucess == true) {
                        Session.Remove("dv<OwnerU>_<TableU>");
                        grd<TableU>.EditIndex = -1;
                        LoadGrid<OwnerU>_<TableU>();
                    } else {
                        ec.ShowMessage(" Update failed. ", " <Head> ");
                    }
                }
            } catch {  
            }
        }

        private void DeleteRecord()
        {
            <TableU> cls<OwnerU>_<TableU> = new <TableU>();
        <If Loop>
           <IsPKey>
            Label lbl<FieldU> = (Label)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("lbl<FieldU>");
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text);
        </If Loop>
        <If Loop>
           <IsNotPKey>
           <And>
           <IsIdentity>
            Label lbl<FieldU> = (Label)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("lbl<FieldU>");
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text);
        </If Loop>
        <If Loop>
           <IsNotIdentityCount>
           <And>
           <IsNotPKeyCount>
            Label lbl<FieldU> = (Label)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("lbl<FieldU>");
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(lbl<FieldU>.Text);
           <ExitLoop>
        </If Loop>
            cls<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.Select_Record(cls<OwnerU>_<TableU>);
            bool bSucess = false;
            bSucess = <OwnerU>_<TableU>DataClass.Delete(cls<OwnerU>_<TableU>);
            if (bSucess == true) {
                Session.Remove("dv<OwnerU>_<TableU>");
                LoadGrid<OwnerU>_<TableU>();
            } else {
                ec.ShowMessage(" Delete failed. ", " <Head> ");
            }
        }

        private Boolean VerifyData()
        {
    <If Loop>
    	<IsCheckBox>
            CheckBox txt<FieldU> = (CheckBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsNumericUpDown>
            TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsDateTimePicker>
            TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsTextBox>
            TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsMaskedTextBox>
            TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsMultilineTextBox>
            TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsRichTextBox>
            TextBox txt<FieldU> = (TextBox)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsComboBox>
            DropDownList txt<FieldU> = (DropDownList)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    	<IsComboBox (Db)>
            DropDownList txt<FieldU> = (DropDownList)grd<TableU>.Rows[Convert.ToInt32(Session["Row"])].FindControl("txt<FieldU>");
    </If Loop>

            <If Loop>
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsCheckBox>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsNumericUpDown>
            if (txt<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txt<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsDateTimePicker>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsTextBox>
            if (txt<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txt<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsMaskedTextBox>
            if (txt<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txt<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsMultilineTextBox>
            if (txt<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txt<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsRichTextBox>
            if (txt<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txt<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsPictureBox>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsComboBox>
            if (txt<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txt<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsComboBox (Db)>
            if (txt<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txt<FieldU>.Focus();
                return false;}
            </If Loop>
            return true;
        }

        private Boolean VerifyDataNew()
        {
    <If Loop>
    	<IsNotIdentity>
    	<And>
    	<IsCheckBox>
            CheckBox txtNew<FieldU> = (CheckBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");

    	<IsNotIdentity>
    	<And>
    	<IsNumericUpDown>
            TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
        <IsNotIdentity>
    	<And>
    	<IsDateTimePicker>
            TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
        <IsNotIdentity>
    	<And>
    	<IsTextBox>
            TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
        <IsNotIdentity>
    	<And>
    	<IsMaskedTextBox>
            TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");

        <IsNotIdentity>
    	<And>
    	<IsMultilineTextBox>
            TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
        <IsNotIdentity>
    	<And>
    	<IsRichTextBox>
            TextBox txtNew<FieldU> = (TextBox)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
        <IsNotIdentity>
    	<And>
    	<IsComboBox>
            DropDownList txtNew<FieldU> = (DropDownList)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
    	<IsNotIdentity>
    	<And>
    	<IsComboBox (Db)>
            DropDownList txtNew<FieldU> = (DropDownList)grd<TableU>.FooterRow.FindControl("txtNew<FieldU>");
    </If Loop>

            <If Loop>
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsCheckBox>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsNumericUpDown>
            if (txtNew<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txtNew<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsDateTimePicker>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsTextBox>
            if (txtNew<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txtNew<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsMaskedTextBox>
            if (txtNew<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txtNew<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsMultilineTextBox>
            if (txtNew<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txtNew<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsRichTextBox>
            if (txtNew<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txtNew<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsPictureBox>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsComboBox>
            if (txtNew<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txtNew<FieldU>.Focus();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsComboBox (Db)>
            if (txtNew<FieldU>.Text == "") {
                ec.ShowMessage(" <FieldC> is Required. ", " <Head> ");
                txtNew<FieldU>.Focus();
                return false;}
            </If Loop>
---------------------------------------<Comment>
            <If Loop>
            <IsNotIdentityCount>
            if (
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsNumericUpDown>
                txtNew<FieldU>.Text != "" 
	            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsTextBox>
                txtNew<FieldU>.Text != "" 
	            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMaskedTextBox>
                txtNew<FieldU>.Text != "" 
	            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMultilineTextBox>
                txtNew<FieldU>.Text != "" 
	            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsRichTextBox>
                txtNew<FieldU>.Text != "" 
	            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsComboBox (Db)>
                txtNew<FieldU>.SelectedIndex != -1 
	            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsNumericUpDown>
            <And>
            <IsCurRow<>[0]>
                && txtNew<FieldU>.Text != "" 
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsTextBox>
            <And>
            <IsCurRow<>[0]>
                && txtNew<FieldU>.Text != "" 
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMaskedTextBox>
            <And>
            <IsCurRow<>[0]>
                && txtNew<FieldU>.Text != "" 
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMultilineTextBox>
            <And>
            <IsCurRow<>[0]>
                && txtNew<FieldU>.Text != ""  
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsRichTextBox>
            <And>
            <IsCurRow<>[0]>
                && txtNew<FieldU>.Text != "" 
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsComboBox (Db)>
            <And>
            <IsCurRow<>[0]>
                && txtNew<FieldU>.SelectedIndex != -1 
            <IsNotIdentity>
            <And>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsNumericUpDown>
                txtNew<FieldU>.Text != "" 
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsTextBox>
                txtNew<FieldU>.Text != "" 
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMaskedTextBox>
                txtNew<FieldU>.Text != "" 
           <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMultilineTextBox>
                txtNew<FieldU>.Text != "" 
           <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsRichTextBox>
                txtNew<FieldU>.Text != "" 
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsComboBox (Db)>
                txtNew<FieldU>.SelectedIndex != -1 
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            )  {
                <TableU> cls<OwnerU>_<TableU> = new <TableU>();
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsNumericUpDown>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsTextBox>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMaskedTextBox>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMultilineTextBox>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsRichTextBox>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsComboBox (Db)>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.SelectedValue);
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsNumericUpDown>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsTextBox>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMaskedTextBox>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMultilineTextBox>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsRichTextBox>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.Text);
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsComboBox (Db)>
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(txtNew<FieldU>.SelectedValue);
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
                cls<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.Select_Record(cls<OwnerU>_<TableU>);
                if (cls<OwnerU>_<TableU> != null) {
                    ec.ShowMessage(" Record already exists. ", " <Head> ");
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsNumericUpDown>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsTextBox>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMaskedTextBox>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMultilineTextBox>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsRichTextBox>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsComboBox (Db)>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsNumericUpDown>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsTextBox>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMaskedTextBox>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMultilineTextBox>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsRichTextBox>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsComboBox (Db)>
                    txtNew<FieldU>.Focus();
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
                    return false; }
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            }
            <ExitLoop>
            </If Loop>
---------------------------------------<Comment>
            return true;
        }

        private string GetSortDirection(string column)
        {
            dynamic sortDirection = "ASC";
            dynamic sortExpression = ViewState["SortExpression"] as string;
            if (sortExpression != null)
            {
                if (sortExpression == column)
                {
                    dynamic lastDirection = ViewState["SortDirection"] as string;
                    if (lastDirection != null && lastDirection == "ASC")
                    {
                        sortDirection = "DESC";
                    }
                }
            }
            ViewState["SortDirection"] = sortDirection;
            ViewState["SortExpression"] = column;
            return sortDirection;
        }

        public void butRecords_Click(object sender, System.EventArgs e)
        {
		    grd<TableU>.PageIndex = 0;
		    grd<TableU>.PageSize = Convert.ToInt32(cmbRecords.Text);
		    LoadGrid<OwnerU>_<TableU>();
        }

        public void butShowAll_Click(object sender, System.EventArgs e)
        {
		    txtSearch.Text = null;
		    Session.Remove("dv<OwnerU>_<TableU>");
		    LoadGrid<OwnerU>_<TableU>();
        }

        public void butSearch_Click(object sender, System.EventArgs e)
        {
		    try {
                        Session.Remove("dv<OwnerU>_<TableU>");
			if ((Session["dv<OwnerU>_<TableU>"] != null)) {
				dv<OwnerU>_<TableU> = (DataView)Session["dv<OwnerU>_<TableU>"];
				// DataView was not found in the session.
		    	} else {
				dv<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.Search(cmbFields.Text, cmbCondition.Text, txtSearch.Text).DefaultView;
			    	Session["dv<OwnerU>_<TableU>"] = dv<OwnerU>_<TableU>;
		    	}
                if (dv<OwnerU>_<TableU>.Count > 0)
                {
                    dv<OwnerU>_<TableU>.Sort = htmlHiddenSortExpression.Value;
                    grd<TableU>.DataSource = dv<OwnerU>_<TableU>;
                    grd<TableU>.DataBind();
                }
                else
                {
                    grd<TableU>.DataSource = null;
                    grd<TableU>.DataBind();
                }
		    }
		    catch (Exception ex)
		    {
		    	ec.ShowMessage(ex.Message, " <Head> ");
		    }
        }

        public void btnExport_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                if (ddlFile.SelectedValue == ".pdf")
                {
                    DataTable dt = new DataTable();
                    if (!string.IsNullOrEmpty(txtSearch.Text))
                    { dt = <OwnerU>_<TableU>DataClass.Search(cmbFields.Text, cmbCondition.Text, txtSearch.Text); }
                    else { dt = <OwnerU>_<TableU>DataClass.SelectAll(); }

                    PDFform pdfForm = new PDFform(dt, "<Head>", "Many");
                    Document document = pdfForm.CreateDocument();
                    PdfDocumentRenderer renderer = new PdfDocumentRenderer(true);
                    renderer.Document = document;
                    renderer.RenderDocument();

                    MemoryStream stream = new MemoryStream();
                    renderer.PdfDocument.Save(stream, false);

                    Response.Clear();
                    Response.ContentType = "application/" + ddlFile.SelectedItem.Text + ddlFile.SelectedValue;
                    Response.AddHeader("content-disposition", "attachment;filename=" + "Report" + ddlFile.SelectedValue);
                    Response.BinaryWrite(stream.ToArray());
                    Response.Flush();
                    Response.End();
                }
                else
                {
                    Response.Clear();
                    Response.Charset = "";
                    Response.ContentEncoding = System.Text.Encoding.UTF8;
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.ContentType = "application/" + ddlFile.SelectedItem.Text + ddlFile.SelectedValue;
                    Response.AddHeader("content-disposition", "attachment;filename=" + "Report" + ddlFile.SelectedValue);

                    System.IO.StringWriter sw = new System.IO.StringWriter();
                    HtmlTextWriter htw = new HtmlTextWriter(sw);
                    GridView GVExport = new GridView();
                    GVExport.DataSource = Session["dv<OwnerU>_<TableU>"];
                    GVExport.DataBind();
                    GVExport.RenderControl(htw);

                    Response.Write(sw);
                    sw = null;
                    htw = null;
                    Response.Flush();
                    Response.End();
                }
            }
            catch
            {
            }
        }

    }
}